<template>
  <div class="login_container">
    <div class="login_wrapper">
      <div class="login_logo">
        <img src="../assets/1.jpg" alt="">
      </div>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0px"
      >
        <el-form-item prop="name" label-width="0">
          <el-input v-model="ruleForm.name" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="password" label-width="0">
          <el-input v-model="ruleForm.password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item label-width="0">
          <el-button type="primary" @click="onClickLogin('ruleForm')"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        password: "",
      },
      rules: {
        name: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  mounted() {},
  methods: {
    onClickLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            console.log(this.ruleForm.name);
            console.log(this.ruleForm.password);
          this.$axios.post("https://www.liulongbin.top:8888/api/private/v1/login", {
            username: this.ruleForm.name,
            password: this.ruleForm.password,
          }).then(res=>{
              console.log(res.data.data);
            console.log(res.data.data.token);
            var token = res.data.data.token;
            localStorage.setItem("token",token);
            this.$router.push("/");
            this.$message("登录成功");
          })
        } else {
          this.$message("登录失败");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.login_container {
  width: 100%;
  height: 100vh;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  .login_wrapper {
    width: 30%;
    height: 45vh;
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    background-color:lightyellow;
    .login_logo{
      width: 100%;
      height: 40px;
      img{
        width: 36px;
        height: 36px;
        border-radius: 50%;
        margin-left:160px;
        margin-top: 10px;
      }
    }
    .el-button--primary {
      width: 100%;
    }
  }
}
</style>